<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Index extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->layout->setLayout('backend');
        $this->load->library(array('session','form_validation','email'));   
        $this->load->helper(array('url','html'));
        $this->load->model('habilitaciones_model'); 
    }
    
    public function index()
    {   
        $this->load->helper('form');
        $this->load->library('form_validation');

        $this->form_validation->set_rules('down', 'Fuera de servicio', 'required');        

        if ($this->form_validation->run() === FALSE)
        {
            $data['title'] = 'Dirección de Habilitaciones';   
            $data['estadoPagina'] = $this->habilitaciones_model->getPageState();   
            if ($data['estadoPagina']=='Deshabilitada') {
                $data['color'] = 'red';
            }else{
                $data['color'] = 'green';                
            }
            $this->load->view('backend',$data); 
        }
        else
        {
            $down = $this->input->post('down'); 
            if ($down == 'Y') {
                      $estado = 'Deshabilitada';                      
            }else
            {
                $estado = 'Habilitada';        
            }
            $data = array('id' => '1','fueradeservicio' => $down, 'estado'=> $estado );            
            $this->habilitaciones_model->setState($data);
            $data['aHabilitaciones'] =$this->habilitaciones_model->getHabilitaciones();
            $data['title'] = 'Dirección de Habilitaciones';         
            if ($down == 'Y') {
                $data['mensaje'] = 'La pagina ha sido deshabilitada.';                     
                $this->load->view('succes',$data); 
            }else
            {
                $data['mensaje'] = 'La pagina ha sido habilitada.';                     
                $this->load->view('succes',$data);     
            }            
        }    
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */